package cn.school.servlet;

import cn.school.entity.Grade;
import cn.school.entity.Student;
import cn.school.service.GradeService;
import cn.school.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

//toUpdateStudent 做跳转，get处理
//updateStudent 做保存，post处理
@WebServlet(name = "ToUpdateStudent",value = {"/toUpdateStudent","/updateStudent"})
public class ToUpdateStudent extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Student student = StudentService.INST.get(Long.parseLong(request.getParameter("stuno")));
        List<Grade> all = GradeService.INST.findALL();
        request.setAttribute("student",student);//???
        request.setAttribute("grades",all);

        request.getRequestDispatcher("/WEB-INF/jsp/student/updateStudent.jsp").forward(request,response);
    }
}
